今天來完成 action client view 最後一個目標
首先先在昨天的銷售總額下方增加一個按鈕
<!-- ironman_js/static/src/xml/action_view.xml -->
<div>
    <h3>銷售總額: <t t-esc="widget.soAmountTotal"/></h3>
		<button type="button" class="btn btn-primary jump-to-so">檢視銷售訂單</button>
</div>
接著增加事件與函式
'click .jump-to-so': '_jump2SO',
_jump2SO: function (ev) {
    const self = this;
    let target = ev.currentTarget;
    target.disabled = true;
    this._rpc({
        model: 'todo.list',
        method: 'jump_to_so',
        args: [[]],
    })
        .then(result => self.do_action(result))
        .catch(() => {
            setTimeout(() => {
                target.disabled = false;
            }, 2000);
        });
},
先請各位先重新整理網頁並點剛剛加的按鈕
各位一定會疑惑還沒有寫 jump_to_so() 函式啊?
是否有注意到筆者在 _rpc() 後方接了一個 catch()
在點下去時先停用按鈕,當錯誤發生時再開放按鈕
防止使用者還在等伺服器回應的時候狂點按鈕,導致要求一直狂打
當然有很多情境可以這樣處理,不一定是錯誤的情況
這就是各位可以依照情況來調整
最後來加上 jump_to_so() 函式吧
# ironman_js/models/todo_list.py
def jump_to_so(self):
    action = self.env.ref('sale.action_quotations_with_onboarding')
    return action.read(fields=('name', 'res_model', 'type', 'views'))[0]
完成後重新啟動伺服器,重新整理網頁後再點一次按鈕,就能看到畫面跳轉囉